package com.example.springboot3.controller;

import com.example.springboot3.pojo.User;
import com.example.springboot3.service.IUserService;
import com.example.springboot3.util.JwtUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张琪
 * @date 2024-02-26 14:42
 */
@RestController
@RequestMapping("/jwt")
public class JwtController {

    @Resource
    private IUserService userService;

    @PostMapping("/login")
    public String login(@RequestBody User user) {
        if ("admin".equals(user.getUsername()) && "admin".equals(user.getPassword())) {
            return JwtUtil.generateToken(user.getUsername());
        }
        return "登陆失败";
    }


    @PostMapping("/api")
    public String api() {
        return userService.doSomething2();
    }
}
